<?php
/**
* @package   auto_occasion
* @subpackage actu
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class BoActuCategorieCtrl extends jController {

    public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );

    /**
    * Liste des categories des actus
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ACTU ;

        jClasses::inc('actu~actuCategorieSrv');
        $cat = actuCategorieSrv::liste();

        $rep->bodyTpl = 'actu~BoActuCategorieList';
        
        $rep->body->assign('cat', $cat);

        return $rep;
    }

    /**
    * Ajout / modif d'une categorie
    */
    function editer() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ACTU ;


        jClasses::inc('actu~actuCategorieSrv');

        $id = $this->intParam('id', '');
        $cat   = ($id) ? actuCategorieSrv::chargeParId($id) : actuCategorieSrv::init();

        $rep->body->assign('cat', $cat);

        $rep->bodyTpl = 'actu~BoActuCategorieEdit';
		
        

        return $rep;
    }

    /**
     * Enregistrer une catégorie
     *
     *
     */
     function sauvegarder() {

        jClasses::inc("actu~actuCategorieSrv");

        $id                = $this->intParam ('id', 0);

        $params = new stdClass();
        $params->ao_cat_name   = $this->stringParam('cat_name', '');
        $params->ao_cat_status = $this->intParam('statut', 0);
        $params->id            = $id;
       
        if ($id) {
            actuCategorieSrv::modifier($params);
        } else {
            actuCategorieSrv::ajouter($params);
        }

        $rep = $this->getResponse('redirect');
        $rep->action = 'actu~BoActuCategorie:index';
        return $rep;
    }

     /**
    * Supprimer une categorie
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');

        jClasses::inc('actu~actuCategorieSrv');
        $id = $this->intParam('id', '');
        actuCategorieSrv::supprimer($id);

        $rep->action = 'actu~BoActuCategorie:index';

        return $rep;
    }



}

